package com.lyz.dataStructure.考研上机编程题;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 19:38
 * @Description:
 **/

import java.util.Scanner;


public class 最大序列和 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i<arr.length;i++){
            arr[i] = sc.nextInt();
         }
        System.out.println(returnNum(arr));
    }

    public static long returnNum(int[] arr){
        if(arr.length==0||arr==null) return 0;
         long maxSum = 0;
         long thisSum = 0;
         for(int i =0;i<arr.length;i++){
             thisSum +=arr[i];
             if(maxSum<thisSum){
                 maxSum=thisSum;
             }else if (thisSum<0){
                 thisSum=0;
             }
         }
         return maxSum;
    }
}
